﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufExtension.h"
#include "GnufUiCommonDef.h"
#include "GnufFilledRegionBoard.h"
#include <QWidget>

namespace gcmp
{
    class UniqueString;
    class IFillPatternData;
    class IFillPattern;
}

namespace gnuf
{
    class AppearanceSetting;
    class Toolbar;
    class ButtonEx;

    class GNUF_EXTENSION_EXPORT QtHatchPatternButtonControl 
        : public QWidget
        , public IItemEventHandler
    {
        Q_OBJECT
    public:
        QtHatchPatternButtonControl(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
        virtual ~QtHatchPatternButtonControl();

    public:
        void setCustomHatchPatternDatas(std::vector<const gcmp::IFillPattern*>&);
        const std::vector<const gcmp::IFillPattern*>& hatchPatternDatas() const;

        bool setCurrentPattern(const std::wstring& curPatternName);
        std::wstring currentPattern() const;

        void setMaxDataColumn(int);
        int maxDataColumn() const { return m_maxColumn; }

        void setHatchPixmapSize(int w, int h) { m_hatchWidth = w; m_hatchHeight = h; }

        void setTextAlign(int align);
        int textAlign() const;

        void setSizeConstraint(ELayoutSizeConstraint);
        ELayoutSizeConstraint sizeConstraint() const;

        void setBorderRadiu(int);
        int borderRadiu();
        
        void reset(const std::wstring&);
    protected:
        virtual void onClicked(Item *) override;

    private:
        void initialize();
        void initControl();
        void initData();
        void build();

    private:
        gcmp::OwnerPtr<Toolbar> m_toolBar;
        gcmp::OwnerPtr<GnufFilledPatternBoard> m_board;
        ButtonEx*  m_button;
        AppearanceSetting* m_setting;
        int m_maxColumn;
        int m_hatchWidth, m_hatchHeight;
    };
}
